package org.lee.framework.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;

import java.time.LocalDate;


/**
 * @author noear 2022/4/17 created
 */
@Slf4j
public class MetaObjectHandlerImpl implements MetaObjectHandler {
    public MetaObjectHandlerImpl() {
        log.info("....MetaObjectHandlerImpl");
    }

    /**
     * 新增时候自动填充
     *
     * @param metaObject metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        try {
            fillStrategy(metaObject, "createTime", LocalDate.now());
            fillStrategy(metaObject, "updateTime", LocalDate.now());
            fillStrategy(metaObject, "delFlag", "0");
        } catch (Exception e) {
            log.error("error message is : {}", e.getMessage(), e);
        }
    }

    /**
     * 修改时候自动填充
     *
     * @param metaObject metaObject
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        try {
            fillStrategy(metaObject, "updateTime", LocalDate.now());
        } catch (Exception e) {
            log.error("error message is : {}", e.getMessage(), e);
        }
    }
}
